//
// Copyright 2001-2004 Stottler Henke Associates, Inc.
// All Rights Reserved.
////////////////////////////////////////////////////////////////////////////////

package com.stottlerhenke.simbionic.engine.core;

import com.stottlerhenke.simbionic.common.*;
import com.stottlerhenke.simbionic.engine.SB_SingletonBook;
import com.stottlerhenke.simbionic.engine.file.SB_StreamReader;
import com.stottlerhenke.simbionic.api.SB_Interface;


/**
 * Base class for all methods that entities can invoke through
 * behavior nodes, including actions and predicates.
 */
public class SB_Method  
{
  protected String      _name;
  protected int  	_id;
  protected SB_ParamList _params;
  transient protected SB_Interface _interface;

  public SB_Method() {
  }
  public SB_Method(String name,int id){
    _name = name;
    _id = id;
    _params = null;
  }
  /**
   * @return the human-readable name of the method
   */
  public String GetName() { return _name; }

  /**
   * @return the unique ID of the method
   */
  public int GetId()  { return _id; }

  /**
   * @return the parameters of the method
   */
  public SB_ParamList GetParams() { return _params; }

  /**
   * @return the SB_Interface that implements this method
   */
  public SB_Interface GetInterface() {return _interface;}

  /**
   * @param iface the SB_Interface that implements this method
   */
  public void SetInterface(SB_Interface iface)
  {
    _interface = iface;
  }

  /**
   * Reads a single method from the specification.
   * @param reader the stream reader from which to reader
   * @param book the singleton container
   * @throws SB_FileException
   */
  public void load(SB_StreamReader reader,SB_SingletonBook book)
		throws SB_FileException
	{
    _name = reader.readPString();
    _id = reader.readInt();

    reader.readSectionTag(SB_StreamReader.TAG_PARAMETERS_START);

    _params = new SB_ParamList();
    _params.load(reader,book);
   }

  public String toString(){
    return new String("Method(" + _name + ", " + _id + ")");
  }


}